home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / allfiles / angry / intro.dir / 00006_gravity.ls < prev    next >
Encoding:
Text File  |  1999-03-01  |  2.6 KB  |  105 lines

  1. property mySpr, mass, velocity, location, timeScale, scale, systemOrigin, frozen, activated, animCount, myAnim, flyMass, pSoftSound, pHardSound
  2. global stageWidth, stageHeight
  3.  
  4. on new me, thisSpr, thisAnim, thisSound
  5.   mySpr = thisSpr
  6.   myAnim = thisAnim
  7.   timeScale = 50
  8.   scale = 5
  9.   pSoftSound = 0
  10.   pHardSound = 0
  11.   if thisSound then
  12.     pSoftSound = thisSound
  13.     pHardSound = thisSound + 1
  14.   end if
  15.   stageWidth = the stageRight - the stageLeft
  16.   stageHeight = the stageBottom - the stageTop
  17.   systemOrigin = [#x: stageWidth / 2, #Y: stageHeight / 2]
  18.   frozen = 0
  19.   activated = 0
  20.   mass = 65
  21.   flyMass = 100
  22.   velocity = [#x: 0, #Y: 0]
  23.   setloc(me)
  24.   return me
  25. end
  26.  
  27. on setloc me
  28.   newX = (the locH of sprite mySpr - systemOrigin.x) * scale
  29.   newY = (the locV of sprite mySpr - systemOrigin.Y) * scale
  30.   location = [#x: newX, #Y: newY]
  31. end
  32.  
  33. on gravitate me
  34.   mouseMass = mass / 2
  35.   flymouseMass = flyMass / 4
  36.   if mySpr = 12 then
  37.     N = flyGravity(mySpr, flyMass, point(the mouseH, the mouseV), flymouseMass, 0, "attract")
  38.   else
  39.     N = calcGravity(mySpr, mass)
  40.   end if
  41.   push(me, N)
  42. end
  43.  
  44. on push me, theForce
  45.   acceleration = theForce / mass
  46.   deltaVelocity = acceleration * timeScale
  47.   velocity = velocity + deltaVelocity
  48.   playSound = 0
  49.   if the bottom of sprite mySpr > stageHeight then
  50.     if velocity.Y > 0 then
  51.       velocity.Y = -velocity.Y
  52.       playSound = 1
  53.     end if
  54.   end if
  55.   if the top of sprite mySpr < 0 then
  56.     if velocity.Y < 0 then
  57.       velocity.Y = -velocity.Y
  58.       playSound = 1
  59.     end if
  60.   end if
  61.   if the left of sprite mySpr < 0 then
  62.     if velocity.x < 0 then
  63.       velocity.x = -velocity.x
  64.       playSound = 1
  65.     end if
  66.   end if
  67.   if the right of sprite mySpr > stageWidth then
  68.     if velocity.x > 0 then
  69.       velocity.x = -velocity.x
  70.       playSound = 1
  71.     end if
  72.   end if
  73.   if playSound and pSoftSound and (random(2) = 2) then
  74.     maxVeloc = max(abs(velocity.x), abs(velocity.Y))
  75.     if maxVeloc > 300 then
  76.       puppetSound(2, pHardSound)
  77.     else
  78.       puppetSound(2, pSoftSound)
  79.     end if
  80.   end if
  81.   move(me)
  82. end
  83.  
  84. on move me
  85.   location = location + velocity
  86.   newLocH = systemOrigin.x + (integer(location.x) / scale)
  87.   newLocV = systemOrigin.Y + (integer(location.Y) / scale)
  88.   set the locH of sprite mySpr to newLocH
  89.   set the locV of sprite mySpr to newLocV
  90. end
  91.  
  92. on animLoop me
  93.   if animCount <> count(myAnim) then
  94.     animCount = animCount + 1
  95.     if animCount >= count(myAnim) then
  96.       animCount = count(myAnim)
  97.     end if
  98.     set the member of sprite mySpr to member(getAt(myAnim, animCount))
  99.   else
  100.     if animCount = count(myAnim) then
  101.       animCount = 0
  102.     end if
  103.   end if
  104. end
  105.